


const HTTP = 'https://agileclubsys.agile.com.cn/api/v1',
    tools = {
        getMoneyInfo(url, data, callback){
            data['login_url'] = window.location.href;
            // data['test'] = 2;

            $.ajax({
                url: HTTP + url,
                data: data,
                async: true,
                type: "GET",
                dataType: "jsonp",
                jsonp: "callback",
                success:  (res) => {
                    if (res.result == -100) {
                        window.location.href = res.login_url; //自动返回授权地址
                    }else if(res.result == -300)  { //未绑定
                        window.location.href = 'economic_login.html';
                    }else if(res.result == -200)  { //未关注
                        window.location.href = 'economic_login.html';
                    }else if(res.result == -301)  { //未关注
                        window.location.href = 'economic_login.html';
                    }else {
                        callback && callback(res);
                    };
                },
                error: () => {
                    
                }
            });
        },
        getInfo(url, data, callback) {
            data['login_url'] = window.location.href;
            // data['test'] = 1;
            let resultStr = window.location.pathname

            $.ajax({
                url: HTTP + url,
                data: data,
                async: true,
                type: "GET",
                dataType: "jsonp",
                jsonp: "callback",
                success:  (res) => {
                    // console.log(res);
                    // return;
                    if (res.result == -100) {
                        window.location.href = res.login_url; //自动返回授权地址
                    }else if(res.result == -300)  { //未绑定
                        window.location.href = 'index.html';
                    }else if(res.result == -200)  { //未关注
                        window.location.href = 'index.html?type=1';
                    }else if(res.result == -301 && resultStr != '/binding.html')  { //已绑定
                        window.location.href = 'binding.html';
                    }else {
                        callback && callback(res);
                    };
                },
                error: () => {
                    
                }
            });
        },
        getQueryString(name) {
            var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
            var r = window.location.search.substr(1).match(reg);
            if (r != null) return unescape(r[2]); return null;
        },
        GetRequest() {   
            var url = location.search; 
            var theRequest = new Object();   
            if (url.indexOf("?") != -1) {  
                var str = url.substr(1);   
                strs = str.split("&");    
                for(var i = 0; i < strs.length; i ++) {  
                    theRequest[strs[i].split("=")[0]]=unescape(strs[i].split("=")[1]);   
                };
                return theRequest;      
            }else{
                return null;   
            };
            
        },   
        getWelcomeText() {
            let now = new Date(), hour = now.getHours(), text='';
            if (hour < 6) { text = "凌晨好" }
            else if (hour < 9) {text ='早上好'; }
            else if (hour < 12) {text = '上午好' }
            else if (hour < 14) {text = '中午好' }
            else if (hour < 17) {text = '下午好' }
            else if (hour < 19) {text = '傍晚好' }
            else if (hour < 22) {text = '晚上好' }
            else { text = '夜里好' }
            return text;
        },
        share(){
            this.getInfo('/Home/Wxshare/index',{
                url:window.location.href 
            },(res)=>{
                // console.log(res);
                var appid = res.obj.appId;
        
                wx.config({
                    debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来，若要查看传入的参数，可以在pc端打开，参数信息会通过log打出，仅在pc端时才会打印。
                    appId: appid, // 必填，公众号的唯一标识
                    timestamp: res.obj.timestamp, // 必填，生成签名的时间戳
                    nonceStr: res.obj.noncestr, // 必填，生成签名的随机串
                    signature: res.obj.signature,// 必填，签名，见附录1
                    jsApiList: [
                        'onMenuShareTimeline',
                         'onMenuShareAppMessage'
                        //  'addCard',
                        //  'chooseCard',
                        //  'openCard'
                    ] // 必填，需要使用的JS接口列表，所有JS接口列表见附录2
                });
                
    
                wx.ready(function(){
                    
                    
                    wx.showOptionMenu();
                    wx.onMenuShareAppMessage({
                        appid: appid,
                        title: '万事达卡fun享有礼', // 分享标题
                        desc: '新开万事达卡即可$0.99畅享星巴克，还有海量优惠等着您！', // 分享描述
                        link: 'https://project.wan888888.com/mostercard1/index.html', // 分享链接
                        imgUrl: 'https://project.wan888888.com/mostercard1/static/images/fx_logo.jpg', // 分享图标
                        success: function () { 
                            
                        },
                        cancel: function () {
                            
                        },
                        trigger:function(){
                            // this.link = fxLink;
                        }
                    });
    
    
                    wx.onMenuShareTimeline({
                        appid:appid,
                        title: '万事达卡fun享有礼', // 分享标题
                        desc: '新开万事达卡即可$0.99畅享星巴克，还有海量优惠等着您！', // 分享描述
                        link: 'https://project.wan888888.com/mostercard1/index.html', // 分享链接
                        imgUrl: 'https://project.wan888888.com/mostercard1/static/images/fx_logo.jpg', // 分享图标
                        success: function () { 
                            
                        },
                        cancel: function () { 
                            
                        },
                        trigger:function(){
                            // this.link = fxLink;
                        }
                    });
    
                });
            });
        },
        disabledWX (){
            wx.hideOptionMenu()

            this.getInfo('/Home/Wxshare/index',{
                url:window.location.href 
            },(res)=>{
                // console.log(res);
                var appid = res.obj.appId;
        
                wx.config({
                    debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来，若要查看传入的参数，可以在pc端打开，参数信息会通过log打出，仅在pc端时才会打印。
                    appId: appid, // 必填，公众号的唯一标识
                    timestamp: res.obj.timestamp, // 必填，生成签名的时间戳
                    nonceStr: res.obj.noncestr, // 必填，生成签名的随机串
                    signature: res.obj.signature,// 必填，签名，见附录1
                    jsApiList: [
                        // 'onMenuShareTimeline',
                        // 'onMenuShareAppMessage'
                        //  'addCard',
                        //  'chooseCard',
                        //  'openCard'
                    ] // 必填，需要使用的JS接口列表，所有JS接口列表见附录2
                });
                
    
                wx.ready(function(){
                    
                    wx.hideOptionMenu();
                    
                });
            });
        },
        loadingImg:''
    };

    tools.disabledWX();

export default tools;
